<HTML><HEAD> <!-- ------------- PSEUDO-1040EZ ------------- --> <SCRIPT LANGUAGE="JavaScript"><!-- hide from old browsers /* THE JAVASCRIPT COOKBOOK by Erica Sadun, webrx@mindspring.com Copyright (c)2000 by Charles River Media. All Rights Reserved. This applet can only be re-used or modifed by license holders of the JavaScript Cookbook CD-ROM. Credit must be given in the source code and this copyright notice must be maintained. If you do not hold a license to the JavaScript Cookbook, you may NOT duplicate or modify this code for your own use. Use at your own risk. No warranty is given or implied of the suitability of this applet for any specific application. Neither Erica Sadun nor Charles River Media will be held responsible for any unwanted effects due to the use of this applet or any derivative. */ // --------------------Math Strings--------------------- // Strip a floating point's digits to #.### -- you set the digits function stripDigits(aNumber, digits) { var str = "" + aNumber var b = str.lastIndexOf(".") // add decimal point if needed if (b < 0) str += "." // pad with extra zeros in case we have too "round" a number for (var i = 0; i < digits; i++) str += "0" // extract existing decimal or just return if (b >= 0) return(str).substring(0,b+1+digits) return str } // Allow for dollar signs in numeric input function stripDollar(aString) { // An empty field means skip and return zero if (aString=="") return 0 // Check if a dollar sign is found var dollar = aString.indexOf("$") var myStr = ""+aString // If so, skip past it if (dollar >= 0) { var len = aString.length myStr = ""+aString.substring(dollar+1, len) } // Evaluate the rest of the string as a floating point return parseFloat(myStr) } // --------------------Tax Calculation--------------------- // Assess the taxes function calculate() { var base, value, rate var adjustedGross = stripDollar(document.forms[0].field1.value) + stripDollar(document.forms[0].field2.value) + stripDollar(document.forms[0].field3.value) document.forms[0].field4.value = "$"+stripDigits(adjustedGross, 2) var deduction = (document.forms[0].field5.options.selectedIndex == 0) ? 6400 : 11550 var taxableIncome = adjustedGross - deduction document.forms[0].field6.value = "$"+stripDigits(taxableIncome, 2) var incomeWithheld = stripDollar(document.forms[0].field7.value) var incomeCredit = stripDollar(document.forms[0].field8.value) var totalPayments = incomeWithheld + incomeCredit document.forms[0].field9.value = "$"+stripDigits(totalPayments, 2) step = 50 if (taxableIncome < 3000) step = 25 if (taxableIncome < 1000) step = 5 if (document.forms[0].field5.options.selectedIndex == 1) // if married { if (taxableIncome < 23350) { base = 0; value = 0; rate = .15 } else if (taxableIncome < 56500) { base = 3502.50; value = 23350; rate = .28 } else if (taxableIncome < 117950) { base = 12798.50; value = 56500; rate = .31 } else if (taxableIncome < 256500) { base = 31832.50; value = 117950; rate = .36 } else { base = 81710.50; value = 256500; rate = .396 } } else { if (taxableIncome < 39000) { base = 0; value = 0; rate = .15 } else if (taxableIncome < 94250) { base = 5850; value = 39000; rate = .28 } else if (taxableIncome < 143600) { base = 21320; value = 94250; rate = .31 } else if (taxableIncome < 256500) { base = 36183.50; value = 143600; rate = .36 } else { base = 77262.50; value = 256500; rate = .396 } } var tmp = taxableIncome - (taxableIncome % step) + step / 2 var taxes = ((tmp - value) * rate + base) document.forms[0].field10.value = "$"+stripDigits(taxes, 2) if (totalPayments < taxes) { document.forms[0].field11.value = "$0.00" document.forms[0].field12.value = "$"+stripDigits(taxes - totalPayments , 2) } else { document.forms[0].field12.value = "$0.00" document.forms[0].field11.value = "$"+stripDigits(totalPayments - taxes, 2) } } <!-- done hiding --></SCRIPT></HEAD> <BODY bgcolor="ffffff"> <FONT COLOR="007777"><H1><IMG SRC="../GRAFX/UTENS.JPG" WIDTH=80 HEIGHT=50 ALIGN = CENTER>Pseudo 1040EZ</H1></FONT> <BLOCKQUOTE><FONT COLOR="770000"> This recipe shows how the JavaScript author can easily adapt paper-based forms into an interactive applet. Use this applet to guestimate your taxes. Enter data after each line in black font. Press the button at the bottom of the form to calculate the aqua lines. </FONT></BLOCKQUOTE> <FONT SIZE=4> <CENTER><FORM NAME="TAXES"><TABLE BORDER=1> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="000000">1: Total wages, salaries, and tips. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field1"></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="000000">2: Taxable interest income of $400 or less. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field2"></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="000000">3: Unemployment compensation. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field3"></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="007777">4: This is your adjusted gross income. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field4"></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="000000">5: If single, enter $6400. If married, enter $11550. </FONT></TD> <TD WIDTH=20%><SELECT NAME="field5" SIZE="1"> <OPTION VALUE="6400">6400<OPTION VALUE="11550">11550</SELECT></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="007777">6: This is your taxable income. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field6"></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="000000">7: Enter your federal income tax withheld. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field7"></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="000000">8: Earned income credit. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field8"></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="007777">9: Total payments. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field9"></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="007777">10: This is your tax. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field10"></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="007777">11: This is your refund. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field11"></TD> </TR> <TR> <TD WIDTH=80%><FONT SIZE=3 COLOR="007777">12: This is the amount you owe. </FONT></TD> <TD WIDTH=20%><INPUT TYPE=TEXT NAME="field12"></TD> </TR> <TR> <TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE="BUTTON" VALUE=" Press to Calculate All AQUA Lines " onClick="calculate()"></TD> </TR> </TABLE><P></CENTER> <FONT COLOR="007777"><H2>Discussion</H2></FONT> <FONT SIZE=4> This JavaScript Applet helps you estimate your taxes. It uses extensive formulas to calculate the taxes you should be assessed. Like the Tailor and Mortgage examples, form data is tightly tied to JavaScript formulas. Please note: results of this sample applet are in no way guaranteed to be correct. </FONT> <h5>Copyright ©1996 by Charles River Media, All Rights Reserved</h5> </BODY> </HTML>